package com.realgodo.site.service.space;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.hibernate.DefaultEntityManager;

import com.realgodo.site.entity.space.SpaceNotice;

@Service("spaceNoticeManager")
@Transactional
public class SpaceNoticeManager extends DefaultEntityManager<SpaceNotice, Long> {

	@Autowired
	protected SessionFactory sessionFactory;

	public Page<SpaceNotice> findSpaceNotices(
			Page<SpaceNotice> spaceNoticePage, Long spaceId) {

		Criteria c = sessionFactory.getCurrentSession().createCriteria(
				SpaceNotice.class);
		c.add(Restrictions.eq("space.id", spaceId));
		c.addOrder(Order.desc("createDate"));

		return this.entityDao.findByCriteria(spaceNoticePage, c);
	}

}
